package com.system.utils;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        List<String> resultList =
                Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12");

        String content1 = resultList.get(0);
        generateWordDocument("起诉书.docx", content1);
        String content2 = resultList.get(1);
        generateWordDocument("立案通知书.docx", content2);
        String content3 = resultList.get(2);
        generateWordDocument("一审判决书.docx", content3);
        String content4 = resultList.get(3);
        generateWordDocument("上诉状.docx", content4);
        String content5 = resultList.get(4);
        generateWordDocument("二审判决书.docx", content5);
        String content6 = resultList.get(5);
        generateWordDocument("执行通知书.docx", content6);
        String content7 = resultList.get(6);
        generateWordDocument("执行裁定书.docx", content7);
        String content8 = resultList.get(7);
        generateWordDocument("结案通知书.docx", content8);
        String content9 = resultList.get(8);
        generateWordDocument("工商数据.docx", content9);
        String content10 = resultList.get(9);
        generateWordDocument("信访数据.docx", content10);
        String content11 = resultList.get(10);
        generateWordDocument("舆情数据.docx", content11);
        String content12 = resultList.get(11);
        generateWordDocument("人物数据关系.docx", content12);
    }

    /**
     * 生成 Word 文档并保存到指定路径
     *
     * @param filePath 文件保存路径（包含文件名）
     * @param content  文档内容
     */
    public static void generateWordDocument(String filePath, String content) {
        File file = new File("D:\\pdf\\" + filePath);
        File parentDir = file.getParentFile();

        // 如果父目录不存在，则创建
        if (parentDir != null && !parentDir.exists()) {
            parentDir.mkdirs();
        }

        try (XWPFDocument document = new XWPFDocument();
             FileOutputStream out = new FileOutputStream("D:\\pdf\\" + filePath)) {

            // 创建一个段落
            XWPFParagraph paragraph = document.createParagraph();
            XWPFRun run = paragraph.createRun();

            // 设置文本内容
            run.setText(content);
            run.setFontSize(12);
            run.setFontFamily("Arial");

            // 保存文档
            document.write(out);
            System.out.println("Word 文档生成成功，保存路径: " + filePath);
        } catch (IOException e) {
            e.printStackTrace();
            System.err.println("生成 Word 文档时出错: " + e.getMessage());
        }
    }


}
